package cn.wf.order.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Description 接收mq消息
 * @Author 万飞
 * @Date 2018/8/12 1:01
 */
@Slf4j
@Component
public class MqReceiver {

//    @RabbitListener(queues = "myQueue")  //1.这里测试需要在mq上手动新建队列myQueue
//    @RabbitListener(queuesToDeclare = @Queue("myQueue")) //2.自动创建队列
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue"),
            exchange = @Exchange("myExchange")
    ))  //3.自动创建，Exchange和Queue绑定
    public void process(String message) {
        log.info("MqReceiver: {}", message);

    }

    /**
     * 数码供应商服务，只接收数码电脑消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "computer",
            value = @Queue("computerOrder")
    ))  //自动创建，Exchange和Queue绑定,key用于分组
    public void processComputer(String message) {
        log.info("computer MqReceiver: {}", message);
    }

    /**
     * 水果供应商服务，只接收水果消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "fruit",
            value = @Queue("fruitOrder")
    ))  //自动创建，Exchange和Queue绑定,key用于分组
    public void processFruit(String message) {
        log.info("fruit MqReceiver: {}", message);
    }
}
